using Game.Core;
using Game.Main.Model;
using Game.Manager;

namespace Game.Component
{
	public class UmberllaItem : BaseItem
	{
		public enum State
		{
			Close = 0,
			Open = 1
		}

		public State state;

		public override void Init(ItemArchiveData data)
		{
			base.Init(data);
		}

		public override void OnAttachItemComplete(bool updatePosition)
		{
			base.OnAttachItemComplete(updatePosition);
			CheckState();
			if (state == State.Open && !updatePosition)
			{
				Singleton<AudioManager>.Instance.PlaySound("sound_umberlla");
			}
		}

		public override void OnReleaseAttachItem(BaseItem oldParent)
		{
			CheckState();
		}

		private void CheckState()
		{
			if (attachType == AttachType.LeftHandTake || attachType == AttachType.RightHandTake)
			{
				SetState(State.Open);
			}
			else
			{
				SetState(State.Close);
			}
		}

		private void SetState(State val)
		{
			if (state != val)
			{
				state = val;
				model.Find("Open").gameObject.SetActive(state != State.Close);
				model.Find("Close").gameObject.SetActive(state == State.Close);
			}
		}
	}
}
